package com.smartum.mpr.business;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.smartum.mpr.dao.NewsImageDao;
import com.smartum.mpr.dao.UserDao;
import com.smartum.mpr.exception.DatabaseIntegrityException;
import com.smartum.mpr.exception.NotExistsTokenException;
import com.smartum.mpr.model.NewsImage;
import com.smartum.mpr.model.User;

@Service
public class NewsImageBusiness extends BaseBusiness {

	@Autowired
	private UserDao userDao;

	@Autowired
	private NewsImageDao newsImageDao;

	public Long addImage(String token, NewsImage image) throws DatabaseIntegrityException, NotExistsTokenException {
		User user = userDao.findUserByToken(token);
		image.setOwner(user);
		newsImageDao.save(image);
		return image.getId();
	}

}
